/*
 * Created on 02.05.2006
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package ro.qi.framework.sys.users.profile.entities;

import java.util.Hashtable;
import java.util.Vector;

import ro.qi.framework.sys.entities.Entity;

/**
 * @author Luiza Varovici
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */

public class UsersAccountProfileGroup extends Entity {

	public UsersAccountProfileGroup() {
		super();
	}

	public UsersAccountProfileGroup(Integer id) {
		super();
		setValue("id", id);
		select();
	}

	public UsersAccountProfileGroup(int id) {
		super();
		setValue("id", new Integer(id));
		select();
	}

	public int getId() {
		return ((Integer)getValue("id")).intValue();
	}

	public void setTitle(String value) {
		setValue("title", value);
	}

	public String getTitle() {
		return (String)getValue("title");
	}

	public void setText(String value) {
		setValue("text", value);
	}

	public String getText() {
		return (String)getValue("text");
	}

	public void setPrevId(int value) {
		setValue("prevId", new Integer(value));
	}

	public int getPrevId() {
		return ((Integer)getValue("prevId")).intValue();
	}

	public void setNextId(int value) {
		setValue("nextId", new Integer(value));
	}

	public int getNextId() {
		return ((Integer)getValue("nextId")).intValue();
	}

	public void setPublished(boolean value) {
		setValue("published", new Integer((value)?1:0));
	}

	public boolean isPublished() {
		return ((Integer)getValue("published")).intValue() == 1;
	}

	public int getNoQuestions() {
		return ((Vector)getValue("questions")).size();
	}
	
	public int getQuestionsId(int index) {
		if( index < getNoQuestions() ) {
			Hashtable tmp = (Hashtable)(((Vector)getValue("questions")).get(index));
			if( tmp.containsKey("questionId") )
				return Integer.parseInt(tmp.get("questionId").toString());
		}
		return 0;
	}
	
	public UsersAccountProfileQuestion getQuestion(int index) {
		int questionId = getQuestionsId(index);
		if( questionId > 0 )
			return new UsersAccountProfileQuestion(questionId);
		return null;
	}
	
	public UsersAccountProfileGroup getNextGroup() {
		if( getNextId() > 0 )
			return new UsersAccountProfileGroup(getNextId());
		return null;
	}

	public UsersAccountProfileQuestion getFirstQuestion() {
		if( getNoQuestions() > 0 ) {
			UsersAccountProfileQuestion question = getQuestion(0);
			while( question.getPrevId() > 0 )
				question = new UsersAccountProfileQuestion(question.getPrevId());
			return question;
		}
		return null;
	}

	public UsersAccountProfileQuestion getLastQuestion() {
		if( getNoQuestions() > 0 ) {
			UsersAccountProfileQuestion question = getQuestion(0);
			while( question.getNextId() > 0 )
				question = new UsersAccountProfileQuestion(question.getNextId());
			return question;
		}
		return null;
	}

}
